home *** CD-ROM | disk | FTP | other *** search
/ Varios Español / Varios Español.iso / DBASE5 / TEMPLATE.ZIP / LABEL.COD < prev    next >
Text File  |  1994-10-12  |  25KB  |  1,129 lines

  1. //
  2. // Module Name: LABEL.COD
  3. // Description: Define label program structure.
  4. //
  5.  
  6. Plantilla para Programa de Etiquetas (.lbg)
  7. -------------------------------------------
  8. Versión 5.0
  9. Copyright (c) 1993,1994 Borland International, Inc.
  10.  
  11. {include "label.def";
  12.  include "builtin.def";
  13.  
  14.  if getenv("dtl_debug") then
  15.    debug(2)
  16.    breakpoint( pick_debug )
  17.  endif
  18.  
  19.  var  bnl_formname,     // Name of BNL file to newframe if argument() has value
  20.       arg_list;
  21.  
  22.  arg_list = argument()
  23.  if arg_list != "" then
  24.    bnl_formname = token( ",", arg_list, 1 )
  25.    if !newframe( bnl_formname ) then
  26.      return -1;
  27.    endif
  28.  endif
  29.  //
  30.  // Enum string constants for international translation
  31.  //
  32.  enum  wrong_class = "Imposible usar LABEL.GEN en objetos que no sean etiquetas.  ",
  33.        label_empty = "Diseño de etiqueta vacío.  ",
  34.       more_samples = "¿Desea más muestras? (S/N)",
  35.       warn_pdriver =
  36. "Las etiquetas no pueden alinearse verticalmente. La tabla de impresora no permite etiquetas laser.",
  37.      error_plength = "La longitud de página debe de ser mayor."
  38.      ;
  39.  //
  40.  if FRAME_CLASS != label then
  41.    pause(wrong_class + any_key);
  42.    return 0;
  43.  endif
  44.  
  45.  //---------------------------
  46.  // Declare working variables
  47.  //---------------------------
  48.  var lblname,       // Name of label file program
  49.      lblpath,       // Path to write label file
  50.      default_drive, // dBASE default drive
  51.      crlf,          // line feed
  52.      line,          // Line counter for outputing number of "?'s"
  53.      isfirst,       // Logical work variable
  54.      mrows,         // Number of rows that the label uses
  55.      mcolumns,      // Number of columns in label
  56.      lbl_vspace,    // Lines between labels
  57.      lbl_wide,      // Label width
  58.      lbl_hspace,    // Number of spaces between labels
  59.      lbl_offset,    // Label left offset
  60.      lbl_widow,     // Determine whether a label will fit on a page
  61.      lbl_lazer,     // Are we using lazerjet labels??
  62.      lbl_textlen,   // Total page text length consumed by lazer labels
  63.      lbl_top,       // Label top margin
  64.      numflds,       // Number of fields used in label
  65.      style,         // Style attribute assigned to the field/text
  66.     current_column, // Current column number
  67.      first_combine, // text or field is first in the chain of combined data
  68.      combine,       // combine fields flag
  69.      new_line,      // is the next field on a new line
  70.  i, j, x, temp, ni, // temporary usage variables
  71.      first_item,    // relative element number when repeating columns
  72.      item_number,   // current item number
  73.      count,         // number of text and field items
  74.     last_row,
  75.     temp_row,
  76.    current_row,
  77.   previous_row,
  78.    blank_line,
  79.   printed_lines,
  80.  previous_element,
  81. number_of_blankable_lines,
  82.  current_element,
  83.     response,
  84.    long_line,       // calculated expression possibly exceeds line
  85.  left_delimiter,
  86.  right_delimiter,
  87.    delimit_flag
  88. ;
  89.  //-------------------------------------------------
  90.  // Assign starting values to some of the variables
  91.  //-------------------------------------------------
  92.  crlf = chr(10);
  93.  current_element=2;
  94.  item_number = isfirst = mcolumns = first_combine = new_line = 1;
  95.  count = line = mrows = numflds = current_column = combine = long_line = 0;
  96.  lbl_vspace = nul2zero(LABEL_VSPACE);
  97.  lbl_wide = LABEL_WIDE;
  98.  lbl_hspace = nul2zero(LABEL_HSPACE);
  99.  lbl_offset = nul2zero(LABEL_LMARG);
  100.  lbl_lazer = lbl_textlen = lbl_top = 0;
  101.  lbl_widow = 1;
  102.  if LABEL_ROWS > 0 then
  103.     lbl_lazer   = 1;
  104.     lbl_textlen = LABEL_ROWS * (LABEL_TALL+LABEL_VSPACE) - 1;
  105.  endif
  106.  
  107.  blank_line = 1;
  108.  current_row = 0;
  109.  previous_row = -1;
  110.  printed_lines = 0;
  111.  previous_element = 0;
  112.  number_of_blankable_lines=0;
  113.  left_delimiter="\""
  114.  right_delimiter="\""
  115.  delimit_flag=0;
  116.  
  117.  foreach ELEMENT ecursor
  118.    if COUNTC(ecursor) > 1 && !eoc(ecursor) then
  119.      temp_row = previous_row = current_row = nul2zero(ROW_POSITN);
  120.      do while !eoc(ecursor)
  121.        if ROW_POSITN > previous_row then
  122.          number_of_blankable_lines=number_of_blankable_lines+blank_line;
  123.          blank_line=1;
  124.          previous_element=0;
  125.          previous_row=ROW_POSITN;
  126.          ++printed_lines;
  127.        endif
  128.        if blank_line then
  129.          if FLD_VALUE_TYPE == 78 then
  130.            if not AT("Z",FLD_PICFUN) then
  131.              blank_line=0;
  132.            endif
  133.          else
  134.            if TEXT_ITEM && !previous_element then
  135.              blank_line=0;
  136.            endif
  137.            if ELEMENT_TYPE == @FLD_ELEMENT && FLD_VALUE_TYPE != 67 then
  138.              blank_line=0;
  139.            endif
  140.          endif
  141.        endif
  142.        if ELEMENT_TYPE == @FLD_ELEMENT && FLD_VALUE_TYPE == 67 ||
  143.        (FLD_VALUE_TYPE == 78 && AT("Z",FLD_PICFUN)) then
  144.          previous_element=1;
  145.        else
  146.          previous_element=0;
  147.        endif
  148.        ++ecursor;
  149.      enddo
  150.      number_of_blankable_lines=number_of_blankable_lines+blank_line;
  151.      ++printed_lines;
  152.      --ecursor;
  153.      previous_row=ROW_POSITN+1;
  154.      last_row=ROW_POSITN;
  155.    endif
  156.  next
  157.  blank_line=0;
  158.  
  159.  default_drive = STRSET(_defdrive);
  160.  lblname = FRAME_PATH + NAME;
  161.  lblpath = FRAME_PATH;
  162.  if not FILEOK(lblname) then
  163.    if FILEDRIVE(NAME) || !default_drive then
  164.      lblname=NAME;
  165.      if FILEDRIVE(NAME) then
  166.        lblpath=FILEDRIVE(NAME)+":"+FILEPATH(NAME);
  167.      else
  168.        lblpath=FILEPATH(NAME);
  169.      endif
  170.    else
  171.      lblname=default_drive + ":" + NAME;
  172.      lblpath=default_drive + ":";
  173.    endif
  174.  endif
  175.  
  176.  if not CREATE(lblname+".LBG") then;
  177.    PAUSE(fileroot(lblname)+".LBG"+read_only+any_key);
  178.    return 0;
  179.  endif
  180. }
  181. * Programa...........: {cap_first(fileroot(lblname))}.LBG
  182. * Fecha..............: {ltrim(substr(date(),1,8))}
  183. * Versión............: dBASE 5.0, Etiquetas
  184. *
  185. * Especificaciones de las etiquetas:
  186. *   Ancho            : {lbl_wide}
  187. *   Altura           : {label_tall}
  188. *   Sangrado         : {nul2zero(label_lmarg)}
  189. *   Columnas         : {label_nup}
  190. *   Espacio entre    : {lbl_hspace}
  191. *   Líneas entre     : {lbl_vspace}
  192. {if lbl_lazer then}
  193. *   Filas por página : {label_rows}
  194. {endif}
  195. *   Líneas en blanco : {number_of_blankable_lines}
  196. *   Líneas impresas  : {printed_lines}
  197. *
  198. PARAMETER ll_sample
  199. *-- Establece los parámetros de impresión para este procedimiento solamente
  200. PRIVATE _peject, _wrap,ln_lines
  201. {if lbl_lazer then}
  202. PRIVATE _pscode,ln_tmargin,_plength,ln_toffset,ll_success,ln_rows
  203. PRIVATE ll_toprint,ll_temp
  204.  
  205. ll_toprint = .F.
  206. ln_tmargin = 0
  207.  
  208. IF SET("PRINTER")="ON"
  209.    IF _plength < {lbl_textlen}
  210.       DO lbl_error WITH "{error_plength}"
  211.       RETURN
  212.    ENDIF
  213.  
  214.    ll_toprint = .T.
  215.    ln_tmargin = (_plength - {lbl_textlen})/2
  216.  
  217.    ln_toffset = ln_tmargin * 240
  218.    ll_success = ESCAPE("QUERY","TMARGIN",ln_toffset)
  219.  
  220.    IF .NOT. ll_success  && no se garantiza el resultado
  221.       DO lbl_error WITH "{warn_pdriver}",.T.
  222.       ln_toffset = 0
  223.    ELSE
  224. *      IF ISBLANK(GETENV("PSCODEFIRST"))
  225. *         _pscode = lc_pscode + _pscode
  226. *      ELSE
  227. *         _pscode = _pscode + lc_pscode
  228. *      ENDIF
  229.        _plength   = {lbl_textlen}
  230.    ENDIF
  231.  
  232. ENDIF
  233. {endif}
  234.  
  235. *-- Comprueba si se ha llegado al final del fichero
  236. IF EOF()
  237.    RETURN
  238. ENDIF
  239.  
  240. IF SET("TALK")="ON"
  241.    SET TALK OFF
  242.    gc_talk="ON"
  243. ELSE
  244.    gc_talk="OFF"
  245. ENDIF
  246. gc_space = SET("SPACE")
  247. SET SPACE OFF
  248. gc_time=TIME()      && tiempo del sistema para el campo predefinido
  249. gd_date=DATE()      && fecha del sistema  "    "    "     "
  250. gl_fandl=.F.        && indicador de primer y último registro
  251. gl_prntflg=.T.      && indicador de continuar impresión
  252. gn_column=1
  253. gn_element=0
  254. gn_line=1
  255. gn_memowid=SET("MEMOWIDTH")
  256. {if lbl_lazer then}
  257. ln_rows=0
  258. {endif}
  259. ln_lines = {label_tall+lbl_vspace}
  260. SET MEMOWIDTH TO 254
  261. gn_page=_pageno     && captura el número de página, gestión de copias múltiples
  262. _plineno=0
  263. _wrap = .F.
  264.  
  265. *-- Establece el entorno
  266. ON ESCAPE DO Prnabort
  267. {if lbl_lazer then}
  268. IF ll_toprint
  269.    ON PAGE AT LINE _plength-1 EJECT PAGE
  270. ENDIF
  271. {endif}
  272.  
  273. {numflds=FRAME_NUM_OF_FIELDS;}
  274. {if LABEL_NUP > 1 then}
  275. *-- Inicializa las matrices para {LABEL_NUP} columna(s) de etiquetas
  276. DECLARE isfound[{LABEL_NUP-1}]
  277. {  if numflds then}
  278. DECLARE tmp4lbl[{LABEL_NUP-1},{numflds}]
  279. {  endif}
  280. {endif}
  281. {//if number_of_blankable_lines then}
  282. DECLARE gn_line2[{label_nup}]
  283. {//endif}
  284.  
  285. PRINTJOB
  286. {if lbl_lazer then}
  287. IF ll_toprint
  288.    ll_temp = ESCAPE("PSIZE",_psize)
  289.    ll_temp = _pwait .AND. ESCAPE("PFEED","MANUAL")
  290.    ll_temp = ESCAPE("VMI",240)
  291.    ll_temp = ESCAPE("TMARGIN",ln_toffset)
  292. ENDIF
  293. {endif}
  294.  
  295. {x=0;}
  296. {foreach FLD_ELEMENT k}
  297. //
  298. // only if there is a fieldname assigned to the calculated field
  299. //
  300. {if FLD_FIELDTYPE == Calc_data && FLD_FIELDNAME then}
  301. {  if !x then}
  302. *-- Inicializa las variables calculadas.
  303. {  endif}
  304. {lower(FLD_FIELDNAME)}=\
  305. {case FLD_VALUE_TYPE of}
  306. {68: // Date   }CTOD(SPACE(8))
  307. {70: // Float  }FLOAT(0)
  308. {76: // Logical}.F.
  309. {78: // Numeric}INT(0)
  310. {otherwise:}""
  311. {endcase}
  312. {  ++x;}
  313. {endif}
  314. {next k;}
  315.  
  316. *-- Establece el número de página para copias múltiples
  317. _pageno=gn_page
  318.  
  319. IF ll_sample
  320.    DO Sample
  321.    IF LASTKEY() = 27
  322.       RETURN
  323.    ENDIF
  324. ENDIF
  325.  
  326. DO WHILE FOUND() .AND. .NOT. EOF() .AND. gl_prntflg
  327. {LMARG(4);}
  328. {if LABEL_NUP > 1 then}
  329. {isfirst=1;}
  330. {x=1;}
  331. STORE .F. TO \
  332. {init_array:}
  333. {if isfirst then}
  334. {  isfirst=0;}
  335. {else}
  336. ,\
  337. {endif}
  338. isfound[{x}]\
  339. {++x;}
  340. {if x < LABEL_NUP then goto init_array endif}
  341.  
  342. {x=0;}
  343. {i=1;}
  344. {arcopy:}
  345. {  if x then}
  346. IF FOUND() .AND. .NOT. EOF()
  347. {    LMARG(7);}
  348. {  endif}
  349. {  calcflds();}
  350. //
  351. {foreach FLD_ELEMENT i}
  352. tmp4lbl[{x+1},{i}]=\
  353. {case FLD_FIELDTYPE of}
  354. {Tabl_data:}
  355. {  if FLD_VALUE_TYPE == 77 then}
  356. MLINE({cap_first(FLD_FIELDNAME)},1)
  357. {  else}
  358. {    cap_first(FLD_FIELDNAME)}
  359.  
  360. {  endif}
  361. {Calc_data:}
  362. {  if FLD_FIELDNAME then}
  363. {    lower(FLD_FIELDNAME)}
  364.  
  365. {  else}
  366. {    foreach FLD_EXPRESSION exp in i}
  367. {      FLD_EXPRESSION}\
  368. {    next}
  369.  
  370. {  endif}
  371. {Pred_data:}
  372. {  case FLD_PREDEFINE of}
  373. {  0: // Date}
  374. gd_date
  375. {  1: // Time}
  376. gc_time
  377. {  2: // Recno}
  378. RECNO()
  379. {  3: // Pageno}
  380. _pageno
  381. {  endcase}
  382. {endcase}
  383. {next i;}
  384. //
  385. {  if x then}
  386. isfound[{x}]=.T.
  387. {  endif}
  388. CONTINUE
  389. {  if x then}
  390. {    LMARG(4);}
  391. ENDIF
  392. {  endif}
  393. {  ++x;}
  394. {  if x < LABEL_NUP-1 then
  395.      goto arcopy;
  396.    endif
  397. }
  398. IF FOUND() .AND. .NOT. EOF()
  399. {LMARG(7);}
  400. {calcflds();}
  401. isfound[{x}]=.T.
  402. {LMARG(4);}
  403. ENDIF
  404. {else}
  405. {calcflds();}
  406. {endif}
  407.  
  408. {x=0;
  409.  do while x < temp_row}
  410. ?
  411. {  ++x;
  412.  enddo
  413. }
  414. gn_line={nul2zero(temp_row)}
  415. *-- Comprueba líneas en blanco
  416. DO Chk4null WITH {nul2zero(temp_row)}, {last_row+1}, {(last_row-temp_row+1)*label_nup}
  417.  
  418. {if lbl_lazer then}
  419. IF ll_toprint
  420.    ln_rows = ln_rows + 1
  421.    IF ln_rows  = {LABEL_ROWS}
  422.       ln_rows  = 0
  423.       ln_lines = {label_tall+lbl_vspace-1}
  424.    ELSE
  425.       ln_lines = {label_tall+lbl_vspace}
  426.    ENDIF
  427. ENDIF
  428. {endif}
  429. DO WHILE gn_line < ln_lines
  430.    ?
  431.    gn_line=gn_line+1
  432. ENDDO
  433. CONTINUE
  434. {LMARG(1);}
  435. ENDDO
  436.  
  437. {if lbl_lazer then}
  438. ON PAGE
  439. {endif}
  440.  
  441. IF .NOT. gl_prntflg
  442.    SET MEMOWIDTH TO gn_memowid
  443.    SET SPACE &gc_space.
  444.    SET TALK &gc_talk.
  445.    ON ESCAPE
  446.    RETURN
  447. ENDIF
  448.  
  449. ENDPRINTJOB
  450.  
  451. {if lbl_lazer then}
  452. IF _plineno # 0
  453.    EJECT PAGE
  454.    ll_temp = _pwait .AND. ESCAPE("PFEED","")
  455. ENDIF
  456. {endif}
  457. SET MEMOWIDTH TO gn_memowid
  458. SET SPACE &gc_space.
  459. SET TALK &gc_talk.
  460. ON ESCAPE
  461. RETURN
  462. * EOP: {cap_first(fileroot(lblname))}.LBG
  463.  
  464. {if lbl_lazer then}
  465.  
  466. PROCEDURE lbl_error
  467. PARAMETER pc_errstr,pl_quickwait
  468.  
  469.    PRIVATE lc_print,lc_console,lc_alter
  470.  
  471.    lc_print   = SET("PRINT")
  472.    lc_console = SET("CONSOLE")
  473.    lc_alter   = SET("ALTERNATE")
  474.  
  475.    SET PRINT OFF
  476.    SET ALTERNATE OFF
  477.    SET CONSOLE ON
  478.  
  479.    DEFINE WINDOW gw_label FROM 7,15 TO 13,64 DOUBLE
  480.    ACTIVATE WINDOW gw_label
  481.    ? pc_errstr AT 1 FUNCTION "V47"
  482.    ?
  483.    ? "{any_key}" AT 1 PICTURE REPLICATE("X",47) FUNCTION "I"
  484.    x=INKEY(IIF(pl_quickwait,4,0))
  485.    DEACTIVATE WINDOW gw_label
  486.    RELEASE WINDOW gw_label
  487.  
  488.    SET CONSOLE &lc_console
  489.    SET ALTERNATE &lc_alter
  490.    SET PRINT &lc_print
  491.  
  492. RETURN
  493. *EOP: lbl_error
  494.  
  495. {endif}
  496.  
  497. PROCEDURE Prnabort
  498. gl_prntflg=.F.
  499. RETURN
  500. * EOP: Prnabort
  501.  
  502. //
  503. // Main loop (inner loop to handles fields on each line by # of columns)
  504. //
  505. {foreach ELEMENT k}
  506. {  if ELEMENT_TYPE == @Band_Element then}
  507. {    ++k; ++item_number;}
  508. {    if eoc(k) then}
  509. {      exit;}
  510. {    endif}
  511. {    temp_row=ROW_POSITN;}
  512. {  endif}
  513. {  ++count;}
  514. {  LMARG(1);}
  515. {  blank_line=0;}
  516. //
  517. {
  518.    if number_of_blankable_lines then
  519.  
  520.      long_line=0;
  521.      blank_line=1;
  522.      current_element=COUNTC(k);
  523.      previous_element=0;
  524.      previous_row=ROW_POSITN;
  525.  
  526.      do while !eoc(k);
  527.        if ROW_POSITN > previous_row then
  528.          exit
  529.        endif
  530.        if blank_line then
  531.          if FLD_VALUE_TYPE == 78 then
  532.            if not AT("Z",FLD_PICFUN) then
  533.              blank_line=0;
  534.            endif
  535.          else
  536.            if TEXT_ITEM && !previous_element then
  537.              blank_line=0;
  538.            endif
  539.            if ELEMENT_TYPE == @FLD_ELEMENT && FLD_VALUE_TYPE != 67 then
  540.              blank_line=0;
  541.            endif
  542.          endif
  543.        endif
  544.        if !blank_line then
  545.          exit
  546.        endif
  547.        if ELEMENT_TYPE == @FLD_ELEMENT && FLD_VALUE_TYPE == 67 ||
  548.        (FLD_VALUE_TYPE == 78 && AT("Z",FLD_PICFUN)) then
  549.          previous_element=1;
  550.        else
  551.          previous_element=0;
  552.        endif
  553.        ++k;
  554.      enddo
  555.      if eoc(k) then
  556.        --k;
  557.      endif
  558.  
  559.      do while COUNTC(k) > current_element;
  560.        --k;
  561.      enddo
  562.  
  563.    endif}
  564. //
  565. //---------------------
  566. // Process blank lines
  567. //---------------------
  568. {  line=temp_row+1;}
  569. {  do while line < ROW_POSITN}
  570. {    x=1;}
  571. {    do while x <= LABEL_NUP}
  572. FUNCTION ___{line}{x}
  573. ll_output=.T.
  574. RETURN .F.
  575.  
  576. {      ++x;}
  577. {    enddo}
  578. {    ++line;}
  579. {  enddo}
  580. //--------------------
  581. // End of blank lines
  582. //--------------------
  583. //
  584. {  mrows = 0;}
  585. {  first_item = item_number;}
  586. {  line = temp_row;}
  587. //
  588. {  repeat:}
  589. //
  590. {  if new_line then}
  591. FUNCTION ___{nul2zero(ROW_POSITN)}{mrows+1}
  592. lc_ret=.F.
  593. {    if mrows then}
  594. *-- Columna {mrows+1}
  595. IF isfound[{mrows}]
  596. {LMARG(4);}
  597. {    endif}
  598. {    if blank_line then}
  599. {      if mrows then}
  600. {        conditional_if_for_blank_line(k,7);}
  601. {      else}
  602. {        conditional_if_for_blank_line(k,4);}
  603. {      endif}
  604. {    else}
  605. ll_output=.T.
  606. {    endif}
  607. ?? \
  608. {  else}
  609. {    if long_line then}
  610. ?? \
  611. {      long_line=0;}
  612. {    else}
  613. ,\
  614. {    endif}
  615. {  endif}
  616. //
  617. {ni=0;}
  618. {  case ELEMENT_TYPE of}
  619. //
  620. {  @Text_Element:}
  621. //
  622. {x=Col_Positn;}
  623. {i=LEN(TEXT_ITEM);}
  624. {if i == 237 then}
  625. {  foreach TEXT_ITEM fcursor in k}
  626. {    if ni then}
  627. {      i=i+LEN(TEXT_ITEM);}
  628. {      temp=TEXT_ITEM;}
  629. {    endif}
  630. {    ++ni;}
  631. {  next}
  632. {endif}
  633. {current_column=x+i;}
  634. //
  635. {  @FLD_ELEMENT:}
  636. //
  637. {x=Col_Positn;}
  638. {i=FLD_REPWIDTH;}
  639. {if i > 237 then}
  640. {  foreach FLD_TEMPLATE fcursor in k}
  641. {    if ni then}
  642. {      temp=FLD_TEMPLATE;}
  643. {    endif}
  644. {    ++ni;}
  645. {  next}
  646. {endif}
  647. {current_column=x+i;}
  648. //
  649. {  endcase}
  650. //
  651. // is the next element on the same line
  652. //
  653. {  line=ROW_POSITN;}
  654. {  ++k;}
  655. {  if (not EOC(k)) && line == ROW_POSITN then}
  656. {    new_line=0;}
  657. //
  658. // is the next element flush with previous element
  659. //
  660. {    if current_column == Col_Positn then}
  661. {      combine=1;}
  662. {    else}
  663. {      combine=0;}
  664. {    endif}
  665. {  else}
  666. {    new_line=1;}
  667. {  endif}
  668. {  --k;}
  669. //-----------------------------------------------
  670. // Determine what type of data we are processing
  671. //-----------------------------------------------
  672. {  case ELEMENT_TYPE of}
  673. //
  674. {  @Text_Element:}
  675. //
  676. {if blank_line then}
  677. IIF( .NOT. ISBLANK( \
  678. {  --k;}
  679. {  if FLD_VALUE_TYPE == 78 then}
  680. TRANSFORM(\
  681. {  endif}
  682. {  if mrows+1 < LABEL_NUP then}
  683. tmp4lbl[{mrows+1},{mcolumns-1}] \
  684. {  else}
  685. {    putfld(k);}
  686. {  endif}
  687. {  if FLD_VALUE_TYPE == 78 then}
  688. ,"@{FLD_PICFUN}")\
  689. {  endif}
  690. {  ++k;}
  691. ),\
  692. {  long_line=1;
  693.  endif}
  694. //
  695. {if substr(TEXT_ITEM,1,1) == "\"" then
  696.    left_delimiter = "["
  697.    right_delimiter = "]"
  698.    delimit_flag = 1;
  699.  endif}
  700. {if i > 70 then}
  701. ;
  702. {  seperate(TEXT_ITEM);}
  703. {  if ni then}
  704. + {left_delimiter}{temp}{right_delimiter};
  705. {  endif}
  706. {else}
  707. {left_delimiter}{TEXT_ITEM}{right_delimiter} \
  708. {endif}
  709. //
  710. {if blank_line then}
  711. ,"" ) \
  712. {endif}
  713. //
  714. {if delimit_flag then
  715.    left_delimiter="\""
  716.    right_delimiter="\""
  717.    delimit_flag=0;
  718.  endif}
  719. {  @FLD_ELEMENT:}
  720. //
  721. {    if mrows+1 < LABEL_NUP then}
  722. tmp4lbl[{mrows+1},{mcolumns}] \
  723. {    else}
  724. {      putfld(k);}
  725. {    endif}
  726. {    ++mcolumns;}
  727. {  endcase}
  728. //
  729. {  if ELEMENT_TYPE == @FLD_ELEMENT && ok_template(k) then}
  730. //
  731. {    if !FLD_FIELDTYPE || FLD_FIELDTYPE == Calc_data ||
  732.         (FLD_FIELDTYPE == Pred_data && FLD_PREDEFINE > 1) then}
  733. //
  734. {      if FLD_VALUE_TYPE == 67 then
  735.          j=FLD_TEMPLATE+temp;
  736.          if FLD_LENGTH == FLD_REPWIDTH && j == REPLICATE("X",FLD_LENGTH) then
  737.            j="";
  738.          endif
  739.        else
  740.          j="1";
  741.        endif}
  742. //
  743. {      if (FLD_PICFUN || j) then}
  744. PICTURE \
  745. {      endif}
  746. //
  747. {      if FLD_PICFUN then}
  748. "@{FLD_PICFUN}\
  749. {        if j then}
  750.  \
  751. {        else}
  752. " \
  753. {        endif}
  754. {      endif}
  755. //
  756. {      if j then}
  757. {        if i > 70 then}
  758. {          if FLD_PICFUN then}
  759. "+;
  760. {          else}
  761. ;
  762. {          endif}
  763. {          seperate(FLD_TEMPLATE);}
  764. {          if ni then}
  765. + "{temp}";
  766. {          endif}
  767. {        else}
  768. {          if !FLD_PICFUN then}
  769. "\
  770. {          endif}
  771. {FLD_TEMPLATE}" \
  772. {        endif}
  773. {      endif}
  774. {    endif}
  775. //
  776. {  endif}
  777. //
  778. {  if FLD_STYLE then}
  779. {    style=getstyle(FLD_STYLE);}
  780. STYLE "{style}" \
  781. {  endif}
  782. {  if first_combine then}
  783. AT {Col_Positn+lbl_offset+(mrows*(lbl_wide+lbl_hspace))} \
  784. {    if combine then}
  785. {      first_combine=0;}
  786. {    endif}
  787. {  else}
  788. {    if not combine then first_combine=1; endif}
  789. {  endif}
  790. //
  791. // position to next element
  792. //
  793. {  temp_row=ROW_POSITN;}
  794. {  ++k; ++item_number;}
  795. //
  796. {  if !new_line || (!EOC(k) && temp_row == ROW_POSITN) then
  797.      if !new_line then}
  798. {      if long_line then}
  799.  
  800. {      else}
  801. ;
  802. {      endif}
  803. {    else}
  804.  
  805. {      long_line=0;}
  806. {    endif
  807.      if !EOC(k) then
  808.        goto repeat;
  809.      endif}
  810. {  else}
  811. {    long_line=0;}
  812. {  endif}
  813. //
  814. {  combine=0;}
  815. {  first_combine=1;}
  816. //
  817. {  if LABEL_NUP-1 > mrows then}
  818.  
  819. {    if blank_line && mrows then}
  820. {      LMARG(4);}
  821. {    else}
  822. {      LMARG(1);}
  823. {    endif}
  824. {    if blank_line then}
  825. {      if temp_row != last_row then}
  826. ELSE
  827.    lc_ret=.T.
  828. {      endif}
  829. ENDIF
  830. {    endif}
  831. {    if mrows then}
  832. {      LMARG(1);}
  833. ENDIF
  834. {    endif}
  835. RETURN lc_ret
  836.  
  837. {    ++mrows;}
  838. {    do while item_number > first_item}
  839. {      --k; --item_number;}
  840. {      if ELEMENT_TYPE == @FLD_ELEMENT then}
  841. {        --mcolumns;}
  842. {      endif}
  843. {    enddo}
  844. {    new_line=1;}
  845. {    goto repeat;}
  846. {  else}
  847.  
  848. {    if mrows then}
  849. {      LMARG(4);}
  850. {    else}
  851. {      LMARG(1);}
  852. {    endif}
  853. {    if blank_line then}
  854. {      if temp_row != last_row then}
  855. ELSE
  856.    lc_ret=.T.
  857. {      endif}
  858. ENDIF
  859. {    endif}
  860. {    if mrows then}
  861. {      LMARG(1);}
  862. ENDIF
  863. {    endif}
  864. RETURN lc_ret
  865.  
  866. {    mrows=0;}
  867. {    --k; --item_number;}
  868. {  endif}
  869. //
  870. {next k;
  871.  
  872. // check for empty label form
  873. if !count then
  874. }
  875.  
  876. PROCEDURE Chk4null
  877. PARAMETERS ln_line, ln_lastrow, ln_element
  878. RETURN
  879. *-- EOP: Chk4null
  880.  
  881. {else}
  882.  
  883. PROCEDURE Chk4null
  884. *-- Parámetros:
  885. *
  886. *-- 1) Número de línea en la superficie de diseño
  887. *-- 2) Número máximo de líneas imprimibles
  888. *-- 3) Parámetro 2 multiplicado por el número de columnas de etiquetas
  889. *
  890. PARAMETERS ln_line, ln_lastrow, ln_element
  891.  
  892. gn_element=0
  893. {
  894.      x=1;
  895.      do while x <= label_nup}
  896. gn_line2[{x}]=ln_line
  897. {      ++x;
  898.      enddo}
  899. lc_temp=SPACE(7)
  900. ll_output=.F.
  901. DO WHILE gn_element < ln_element
  902.    gn_column=1
  903.    ll_output=.F.
  904.    DO WHILE gn_column <= {label_nup}
  905.       IF gn_line2[gn_column] < ln_lastrow
  906.          lc_temp=LTRIM(STR(gn_line2[gn_column]))+LTRIM(STR(gn_column))
  907.          DO WHILE ___&lc_temp.()
  908.             gn_element=gn_element+1
  909.             gn_line2[gn_column]=gn_line2[gn_column]+1
  910.             lc_temp=LTRIM(STR(gn_line2[gn_column]))+LTRIM(STR(gn_column))
  911.          ENDDO
  912.          gn_element=gn_element+1
  913.          gn_line2[gn_column]=gn_line2[gn_column]+1
  914.       ENDIF
  915.       gn_column=gn_column+1
  916.    ENDDO
  917.    IF ll_output
  918.      ?
  919.      gn_line=gn_line+1
  920.    ENDIF
  921. ENDDO
  922. RETURN
  923. *-- EOP: Chk4null
  924. {endif                // label form empty check}
  925.  
  926. PROCEDURE Sample
  927. PRIVATE x,y,choice
  928. DEFINE WINDOW w4sample FROM 15,20 TO 17,60 DOUBLE
  929. choice="S"
  930. x=0
  931. DO WHILE choice = "S"
  932.    y=0
  933.    DO WHILE y < {LABEL_TALL}
  934.       x=0
  935.       DO WHILE x < {LABEL_NUP}
  936. {if lbl_offset then}
  937.          IF x = 0
  938.             ?? "" AT {lbl_offset}
  939.          ENDIF
  940. {endif}
  941.          ?? REPLICATE("X",{LABEL_WIDE})\
  942. {if LABEL_HSPACE then}
  943. +SPACE({LABEL_HSPACE})
  944. {else}
  945.  
  946. {endif}
  947.          x=x+1
  948.       ENDDO
  949.       ?
  950.       y=y+1
  951.    ENDDO
  952. {if LABEL_VSPACE then}
  953.    x=0
  954.    DO WHILE x < {LABEL_VSPACE}
  955.       ?
  956.       x=x+1
  957.    ENDDO
  958. {endif}
  959.    ACTIVATE WINDOW w4sample
  960.    @ 0,3 SAY "{more_samples}";
  961.    GET choice PICTURE "!" VALID choice $ "NS"
  962.    READ
  963.    DEACTIVATE WINDOW w4sample
  964.    IF LASTKEY() = 27
  965.       EXIT
  966.    ENDIF
  967. ENDDO
  968. RELEASE WINDOW w4sample
  969. RETURN
  970. * EOP: Sample
  971.  
  972. {return 0;}
  973. //--------------------------------
  974. // End of main template procedure
  975. // User defined function follows
  976. //--------------------------------
  977. {
  978.  define getstyle(mstyle);
  979.   var outstyle;
  980.   outstyle="";
  981.   if Bold        & mstyle then outstyle=outstyle+"B"; endif
  982.   if Italic      & mstyle then outstyle=outstyle+"I"; endif
  983.   if Underline   & mstyle then outstyle=outstyle+"U"; endif
  984.   if Superscript & mstyle then outstyle=outstyle+"R"; endif
  985.   if Subscript   & mstyle then outstyle=outstyle+"L"; endif
  986.   if User_Font   & mstyle then
  987.     if  1 & mstyle then outstyle=outstyle+"1"; endif
  988.     if  2 & mstyle then outstyle=outstyle+"2"; endif
  989.     if  4 & mstyle then outstyle=outstyle+"3"; endif
  990.     if  8 & mstyle then outstyle=outstyle+"4"; endif
  991.     if 16 & mstyle then outstyle=outstyle+"5"; endif
  992.   endif
  993. return outstyle;
  994. enddef;
  995.  
  996. define ok_template(cur)
  997.      if cur.FLD_TEMPLATE && !(chr(cur.FLD_VALUE_TYPE) == "D" ||
  998.                               chr(cur.FLD_VALUE_TYPE) == "G" ||
  999.                               chr(cur.FLD_VALUE_TYPE) == "B"
  1000.                   ) then
  1001.         return 1;
  1002.      else
  1003.         return 0;
  1004.      endif
  1005. enddef
  1006.  
  1007. }
  1008. {define putfld(cursor);
  1009.  var value,value2;
  1010.  value=cursor.FLD_FIELDTYPE;}
  1011. {       if mrows+1 < LABEL_NUP then}
  1012. tmp4lbl[{mrows+1},{mcolumns}] \
  1013. {       else}
  1014. {case value of}
  1015. {Tabl_data:}
  1016. {  if cursor.FLD_VALUE_TYPE == 77 then}
  1017. MLINE({cap_first(cursor.FLD_FIELDNAME)},1)\
  1018. {  else}
  1019. {    cap_first(cursor.FLD_FIELDNAME)}\
  1020. {  endif}
  1021. {Calc_data:}
  1022. {  if cursor.FLD_FIELDNAME then}
  1023. {    lower(cursor.FLD_FIELDNAME)}\
  1024. {  else}
  1025. {    foreach FLD_EXPRESSION exp in cursor}
  1026. {      FLD_EXPRESSION}\
  1027. {    next}
  1028.  ;
  1029. {    long_line=1;}
  1030. {  endif}
  1031. {Pred_data:}
  1032. {  value2=cursor.FLD_PREDEFINE;}
  1033. {  case value2 of}
  1034. {  0: // Date}
  1035. gd_date\
  1036. {  1: // Time}
  1037. gc_time\
  1038. {  2: // Recno}
  1039. RECNO()\
  1040. {  3: // Pageno}
  1041. _pageno\
  1042. {  endcase}
  1043. {endcase}
  1044.  \
  1045. {       endif}
  1046. {return;
  1047. enddef;
  1048. }
  1049. {
  1050.  define conditional_if_for_blank_line(cursor2, page_offset);
  1051.  var field_flag, current_row;
  1052. }
  1053. *-- Comprueba si hay línea en blanco
  1054. IF .NOT. ISBLANK( \
  1055. {
  1056.        current_element=COUNTC(cursor2);
  1057.        current_row=cursor2.ROW_POSITN;
  1058.        do while !eoc(cursor2) && cursor2.ROW_POSITN == current_row}
  1059. {        if cursor2.ELEMENT_TYPE == @FLD_ELEMENT then
  1060.            if field_flag then}+ \
  1061. {          else
  1062.              field_flag=1;
  1063.            endif
  1064.          endif
  1065.          if cursor2.FLD_VALUE_TYPE == 78 then}
  1066. TRANSFORM(\
  1067. {          putfld(cursor2);}
  1068. ,"\
  1069. {          if cursor2.FLD_PICFUN then}
  1070. @{cursor2.FLD_PICFUN} \
  1071. {          endif}
  1072. {cursor2.FLD_TEMPLATE}") \
  1073. {//
  1074.          else
  1075.            if cursor2.ELEMENT_TYPE == @FLD_ELEMENT then
  1076.              putfld(cursor2);
  1077.            endif
  1078.          endif
  1079.          if cursor2.ELEMENT_TYPE == @FLD_ELEMENT then
  1080.            ++mcolumns;
  1081.          endif
  1082.          ++cursor2;
  1083.        enddo
  1084.        do while eoc(cursor2) || COUNTC(cursor2) > current_element;
  1085.          --cursor2;
  1086.          if cursor2.ELEMENT_TYPE == @FLD_ELEMENT then
  1087.            --mcolumns;
  1088.          endif
  1089.        enddo}
  1090. )
  1091. {LMARG(page_offset);}
  1092. ll_output=.T.
  1093. {  return;
  1094.  enddef
  1095. }
  1096. {define calcflds();}
  1097. {foreach FLD_ELEMENT k}
  1098. {  if FLD_FIELDNAME && FLD_FIELDTYPE == Calc_data then}
  1099. {lower(FLD_FIELDNAME)}=\
  1100. {foreach FLD_EXPRESSION j in k}
  1101. {FLD_EXPRESSION}
  1102. {next}
  1103.  
  1104. {  endif}
  1105. {next k;}
  1106. {return;}
  1107. {enddef}
  1108. {
  1109.  define seperate(string);
  1110.  var x,y,length;
  1111.  x=1;
  1112.  length=LEN(string);
  1113.  moreleft:
  1114.  if x < length then
  1115.    if x != 1 then}
  1116. + \
  1117. {  endif
  1118.    if x+70 <= length then y=70; else y=length-x+1; endif}
  1119. "{SUBSTR(string,x,y)}";
  1120. {  x=x+70;
  1121.    goto moreleft;
  1122.  endif
  1123.  return;
  1124.  enddef
  1125. }
  1126.  
  1127.  
  1128. // EOP: LABEL.COD
  1129.